package com.xxl.job.admin.rest;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import com.ibm.risk.common.rest.RestService;
import com.xxl.job.admin.core.model.JobInfo;
import com.xxl.job.admin.dao.IJobGroupDao;
import com.xxl.job.admin.service.IJobService;
import com.xxl.job.core.biz.model.ReturnT;

/**
 * index controller
 * 
 * @author xuxueli 2015-12-19 16:13:16
 */
@RestService
@Path("/jobinfo")
public class JobInfoResource {

	@Resource
	private IJobGroupDao xxlJobGroupDao;
	@Resource
	private IJobService xxlJobService;

	@Path("/pageList")
	@GET
	public Map<String, Object> pageList(@QueryParam("start") int start, @QueryParam("length") int length,
		@QueryParam("jobGroup") Long jobGroup, @QueryParam("executorHandler") String executorHandler,
		@QueryParam("filterTime") String filterTime) {

		return xxlJobService.pageList(start, length, jobGroup, executorHandler, filterTime);
	}

	@Path("/add")
	@POST
	public ReturnT<String> add(JobInfo jobInfo) {
		jobInfo.setAddTime(new Date());
		jobInfo.setUpdateTime(jobInfo.getAddTime());
		return xxlJobService.add(jobInfo);
	}

	@Path("/reschedule")
	@PUT
	public ReturnT<String> reschedule(JobInfo jobInfo) {
		return xxlJobService.reschedule(jobInfo);
	}

	@Path("/remove/{id}")
	@DELETE
	public ReturnT<String> remove(@PathParam("id") Long id) {
		return xxlJobService.remove(id);
	}

	@Path("/pause//{id}")
	@POST
	public ReturnT<String> pause(@PathParam("id") Long id) {
		return xxlJobService.pause(id);
	}

	@Path("/resume/{id}")
	@POST
	public ReturnT<String> resume(@PathParam("id") Long id) {
		return xxlJobService.resume(id);
	}

	@Path("/trigger/{id}")
	@POST
	public ReturnT<String> triggerJob(@PathParam("id") Long id) {
		return xxlJobService.triggerJob(id);
	}

}
